Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright.
Check the package website, https://docs.ropensci.org/osmextract/, for more details.
Code
library(tigris)
To enable caching of data, set `options(tigris_use_cache = TRUE)`
in your R script or .Rprofile.
Code
library(mapview)library(lehdr)library(viridis)
Loading required package: viridisLite
Code
library(viridisLite)library(spatstat)
Loading required package: spatstat.data
Loading required package: spatstat.univar
spatstat.univar 3.1-5
Loading required package: spatstat.geom
spatstat.geom 3.6-1
Loading required package: spatstat.random
spatstat.random 3.4-3
Loading required package: spatstat.explore
Loading required package: nlme
Attaching package: 'nlme'
The following object is masked from 'package:dplyr':
collapse
spatstat.explore 3.6-0
Loading required package: spatstat.model
Loading required package: rpart
spatstat.model 3.5-0
Loading required package: spatstat.linnet
spatstat.linnet 3.4-0
spatstat 3.5-0
For an introduction to spatstat, type 'beginner'
Code
library(units)
udunits database from /usr/share/xml/udunits/udunits2.xml
Code
library(spdep)
Loading required package: spData
To access larger datasets in this package, install the spDataLarge
package with: `install.packages('spDataLarge',
repos='https://nowosad.github.io/drat/', type='source')`
Code
library(terra)
terra 1.8.86
Attaching package: 'terra'
The following objects are masked from 'package:spatstat.geom':
area, delaunay, is.empty, rescale, rotate, shift, where.max,
where.min
The following object is masked from 'package:tigris':
blocks
Code
library(raster)
Loading required package: sp
Attaching package: 'raster'
The following object is masked from 'package:nlme':
getData
The following object is masked from 'package:dplyr':
select
Code
library(tictoc)
Attaching package: 'tictoc'
The following object is masked from 'package:raster':
shift
The following objects are masked from 'package:terra':
shift, size
The following object is masked from 'package:spatstat.geom':
shift
Moran I test under randomisation
data: inv_dist
weights: lw
Moran I statistic standard deviate = 35.752, p-value < 2.2e-16
alternative hypothesis: greater
sample estimates:
Moran I statistic Expectation Variance
0.8444759043 -0.0012936611 0.0005596277
Moran I test under randomisation
data: inv_dist
weights: lw
Moran I statistic standard deviate = 48.697, p-value < 2.2e-16
alternative hypothesis: greater
sample estimates:
Moran I statistic Expectation Variance
0.6827748494 -0.0004344049 0.0001968368
Moran I test under randomisation
data: inv_dist
weights: lw
Moran I statistic standard deviate = 23.091, p-value < 2.2e-16
alternative hypothesis: greater
sample estimates:
Moran I statistic Expectation Variance
0.842640558 -0.003134796 0.001341649
Moran I test under randomisation
data: inv_dist
weights: lw
Moran I statistic standard deviate = 12.936, p-value < 2.2e-16
alternative hypothesis: greater
sample estimates:
Moran I statistic Expectation Variance
0.808442476 -0.009433962 0.003997522
Moran I test under randomisation
data: inv_dist
weights: lw
Moran I statistic standard deviate = 43.616, p-value < 2.2e-16
alternative hypothesis: greater
sample estimates:
Moran I statistic Expectation Variance
0.9584339511 -0.0011013216 0.0004839866
Warning: Values of the covariate 'pop_im' were NA or undefined at 4.3% (345 out
of 8083) of the quadrature points. Occurred while executing: ppm.ppp(Q =
dock_ppp, trend = ~pop_im, data = NULL, interaction = NULL)
Code
summary(m1)
Point process model
Fitted to data: dock_ppp
Fitting method: maximum likelihood (Berman-Turner approximation)
Model was fitted using glm()
Algorithm converged
Call:
ppm.formula(Q = dock_ppp ~ pop_im)
Edge correction: "border"
[border correction distance r = 0 ]
--------------------------------------------------------------------------------
Quadrature scheme (Berman-Turner) = data + dummy + weights
Data pattern:
Planar point pattern: 2303 points
Average intensity 5.99e-06 points per square unit
Window: polygonal boundary
single connected closed polygon with 137 vertices
enclosing rectangle: [576179.5, 597719.6] x [4495675, 4527093] units
(21540 x 31420 units)
Window area = 384647000 square units
Fraction of frame area: 0.568
Dummy quadrature points:
100 x 100 grid of dummy points, plus 4 corner points
dummy spacing: 215.4011 x 314.1755 units
Original dummy parameters: =
Planar point pattern: 5780 points
Average intensity 1.5e-05 points per square unit
Window: polygonal boundary
single connected closed polygon with 137 vertices
enclosing rectangle: [576179.5, 597719.6] x [4495675, 4527093] units
(21540 x 31420 units)
Window area = 384647000 square units
Fraction of frame area: 0.568
Quadrature weights:
(counting weights based on 100 x 100 array of rectangular tiles)
All weights:
range: [8530, 67700] total: 3.84e+08
Weights on data points:
range: [11300, 33800] total: 69200000
Weights on dummy points:
range: [8530, 67700] total: 3.15e+08
--------------------------------------------------------------------------------
FITTED :
Nonstationary Poisson process
---- Intensity: ----
Log intensity: ~pop_im
Model depends on external covariate 'pop_im'
Covariates provided:
pop_im: im
Fitted trend coefficients:
(Intercept) pop_im
-1.237567e+01 2.121081e-05
Estimate S.E. CI95.lo CI95.hi Ztest
(Intercept) -1.237567e+01 3.074223e-02 -1.243592e+01 -1.231541e+01 ***
pop_im 2.121081e-05 9.451471e-07 1.935836e-05 2.306327e-05 ***
Zval
(Intercept) -402.56236
pop_im 22.44181
----------- gory details -----
Fitted regular parameters (theta):
(Intercept) pop_im
-1.237567e+01 2.121081e-05
Fitted exp(theta):
(Intercept) pop_im
4.220043e-06 1.000021e+00
Problem:
Values of the covariate 'pop_im' were NA or undefined at 4.3% (345 out of 8083) of the quadrature points
Code
anova(m0, m1, test="LR")
Warning: Values of the covariate 'pop_im' were NA or undefined at 4.3% (345 out
of 8083) of the quadrature points. Occurred while executing: ppm.ppp(Q =
dock_ppp, trend = ~pop_im, data = NULL, interaction = NULL,
Warning: Models were re-fitted after discarding quadrature points that were
illegal under some of the models
Warning: Values of the covariate 'pop_im' were NA or undefined at 4.4% (145 out
of 3260) of the quadrature points. Occurred while executing: ppm.ppp(Q =
dock_ppp, trend = ~pop_im, data = NULL, interaction = NULL)
Code
summary(m1)
Point process model
Fitted to data: dock_ppp
Fitting method: maximum likelihood (Berman-Turner approximation)
Model was fitted using glm()
Algorithm converged
Call:
ppm.formula(Q = dock_ppp ~ pop_im)
Edge correction: "border"
[border correction distance r = 0 ]
--------------------------------------------------------------------------------
Quadrature scheme (Berman-Turner) = data + dummy + weights
Data pattern:
Planar point pattern: 320 points
Average intensity 1.17e-06 points per square unit
Window: polygonal boundary
single connected closed polygon with 127 vertices
enclosing rectangle: [812090.4, 831648.2] x [4686171, 4706029] units
(19560 x 19860 units)
Window area = 272770000 square units
Fraction of frame area: 0.702
Dummy quadrature points:
64 x 64 grid of dummy points, plus 4 corner points
dummy spacing: 305.5909 x 310.2755 units
Original dummy parameters: =
Planar point pattern: 2940 points
Average intensity 1.08e-05 points per square unit
Window: polygonal boundary
single connected closed polygon with 127 vertices
enclosing rectangle: [812090.4, 831648.2] x [4686171, 4706029] units
(19560 x 19860 units)
Window area = 272770000 square units
Fraction of frame area: 0.702
Quadrature weights:
(counting weights based on 64 x 64 array of rectangular tiles)
All weights:
range: [12100, 94800] total: 2.72e+08
Weights on data points:
range: [19000, 47400] total: 13400000
Weights on dummy points:
range: [12100, 94800] total: 2.59e+08
--------------------------------------------------------------------------------
FITTED :
Nonstationary Poisson process
---- Intensity: ----
Log intensity: ~pop_im
Model depends on external covariate 'pop_im'
Covariates provided:
pop_im: im
Fitted trend coefficients:
(Intercept) pop_im
-1.418988e+01 9.188116e-05
Estimate S.E. CI95.lo CI95.hi Ztest
(Intercept) -1.418988e+01 8.618496e-02 -1.435880e+01 -1.402096e+01 ***
pop_im 9.188116e-05 8.049611e-06 7.610421e-05 1.076581e-04 ***
Zval
(Intercept) -164.64449
pop_im 11.41436
----------- gory details -----
Fitted regular parameters (theta):
(Intercept) pop_im
-1.418988e+01 9.188116e-05
Fitted exp(theta):
(Intercept) pop_im
6.877236e-07 1.000092e+00
Problem:
Values of the covariate 'pop_im' were NA or undefined at 4.4% (145 out of 3260) of the quadrature points
Code
anova(m0, m1, test="LR")
Warning: Values of the covariate 'pop_im' were NA or undefined at 4.4% (145 out
of 3260) of the quadrature points. Occurred while executing: ppm.ppp(Q =
dock_ppp, trend = ~pop_im, data = NULL, interaction = NULL,
Warning: Models were re-fitted after discarding quadrature points that were
illegal under some of the models
Warning: Values of the covariate 'pop_im' were NA or undefined at 0.66% (6 out
of 912) of the quadrature points. Occurred while executing: ppm.ppp(Q =
dock_ppp, trend = ~pop_im, data = NULL, interaction = NULL)
Code
summary(m1)
Point process model
Fitted to data: dock_ppp
Fitting method: maximum likelihood (Berman-Turner approximation)
Model was fitted using glm()
Algorithm converged
Call:
ppm.formula(Q = dock_ppp ~ pop_im)
Edge correction: "border"
[border correction distance r = 0 ]
--------------------------------------------------------------------------------
Quadrature scheme (Berman-Turner) = data + dummy + weights
Data pattern:
Planar point pattern: 107 points
Average intensity 8.44e-07 points per square unit
Window: polygonal boundary
single connected closed polygon with 136 vertices
enclosing rectangle: [-3757195, -3744439] x [5412459, 5425830] units
(12760 x 13370 units)
Window area = 126726000 square units
Fraction of frame area: 0.743
Dummy quadrature points:
32 x 32 grid of dummy points, plus 4 corner points
dummy spacing: 398.6460 x 417.8386 units
Original dummy parameters: =
Planar point pattern: 805 points
Average intensity 6.35e-06 points per square unit
Window: polygonal boundary
single connected closed polygon with 136 vertices
enclosing rectangle: [-3757195, -3744439] x [5412459, 5425830] units
(12760 x 13370 units)
Window area = 126726000 square units
Fraction of frame area: 0.743
Quadrature weights:
(counting weights based on 32 x 32 array of rectangular tiles)
All weights:
range: [7200, 167000] total: 1.27e+08
Weights on data points:
range: [41600, 83300] total: 8120000
Weights on dummy points:
range: [7200, 167000] total: 1.19e+08
--------------------------------------------------------------------------------
FITTED :
Nonstationary Poisson process
---- Intensity: ----
Log intensity: ~pop_im
Model depends on external covariate 'pop_im'
Covariates provided:
pop_im: im
Fitted trend coefficients:
(Intercept) pop_im
-1.432761e+01 3.904106e-05
Estimate S.E. CI95.lo CI95.hi Ztest
(Intercept) -1.432761e+01 1.743289e-01 -1.466929e+01 -1.398594e+01 ***
pop_im 3.904106e-05 1.500172e-05 9.638223e-06 6.844389e-05 **
Zval
(Intercept) -82.187281
pop_im 2.602438
----------- gory details -----
Fitted regular parameters (theta):
(Intercept) pop_im
-1.432761e+01 3.904106e-05
Fitted exp(theta):
(Intercept) pop_im
5.992334e-07 1.000039e+00
Problem:
Values of the covariate 'pop_im' were NA or undefined at 0.66% (6 out of 912) of the quadrature points
Code
anova(m0, m1, test="LR")
Warning: Values of the covariate 'pop_im' were NA or undefined at 0.66% (6 out
of 912) of the quadrature points. Occurred while executing: ppm.ppp(Q =
dock_ppp, trend = ~pop_im, data = NULL, interaction = NULL,
Warning: Models were re-fitted after discarding quadrature points that were
illegal under some of the models
Warning: Values of the covariate 'pop_im' were NA or undefined at 10% (444 out
of 4391) of the quadrature points. Occurred while executing: ppm.ppp(Q =
dock_ppp, trend = ~pop_im, data = NULL, interaction = NULL)
Code
summary(m1)
Point process model
Fitted to data: dock_ppp
Fitting method: maximum likelihood (Berman-Turner approximation)
Model was fitted using glm()
Algorithm converged
Call:
ppm.formula(Q = dock_ppp ~ pop_im)
Edge correction: "border"
[border correction distance r = 0 ]
--------------------------------------------------------------------------------
Quadrature scheme (Berman-Turner) = data + dummy + weights
Data pattern:
Planar point pattern: 909 points
Average intensity 9.85e-07 points per square unit
Window: polygonal boundary
single connected closed polygon with 131 vertices
enclosing rectangle: [-566382.1, -541021] x [4685608, 4737799] units
(25360 x 52190 units)
Window area = 922506000 square units
Fraction of frame area: 0.697
Dummy quadrature points:
70 x 70 grid of dummy points, plus 4 corner points
dummy spacing: 362.3008 x 745.5848 units
Original dummy parameters: =
Planar point pattern: 3482 points
Average intensity 3.77e-06 points per square unit
Window: polygonal boundary
single connected closed polygon with 131 vertices
enclosing rectangle: [-566382.1, -541021] x [4685608, 4737799] units
(25360 x 52190 units)
Window area = 922506000 square units
Fraction of frame area: 0.697
Quadrature weights:
(counting weights based on 70 x 70 array of rectangular tiles)
All weights:
range: [24600, 270000] total: 9.21e+08
Weights on data points:
range: [24600, 135000] total: 1.08e+08
Weights on dummy points:
range: [24600, 270000] total: 8.14e+08
--------------------------------------------------------------------------------
FITTED :
Nonstationary Poisson process
---- Intensity: ----
Log intensity: ~pop_im
Model depends on external covariate 'pop_im'
Covariates provided:
pop_im: im
Fitted trend coefficients:
(Intercept) pop_im
-1.419576e+01 9.193927e-05
Estimate S.E. CI95.lo CI95.hi Ztest
(Intercept) -1.419576e+01 4.680314e-02 -1.428750e+01 -1.410403e+01 ***
pop_im 9.193927e-05 4.699411e-06 8.272859e-05 1.011499e-04 ***
Zval
(Intercept) -303.3079
pop_im 19.5640
----------- gory details -----
Fitted regular parameters (theta):
(Intercept) pop_im
-1.419576e+01 9.193927e-05
Fitted exp(theta):
(Intercept) pop_im
6.836891e-07 1.000092e+00
Problem:
Values of the covariate 'pop_im' were NA or undefined at 10% (444 out of 4391) of the quadrature points
Code
anova(m0, m1, test="LR")
Warning: Values of the covariate 'pop_im' were NA or undefined at 10% (444 out
of 4391) of the quadrature points. Occurred while executing: ppm.ppp(Q =
dock_ppp, trend = ~pop_im, data = NULL, interaction = NULL,
Warning: Models were re-fitted after discarding quadrature points that were
illegal under some of the models